<!-- 轮播图控件设置面板 -->
<template>
    <el-tabs modelValue="widget" stretch>
        <el-tab-pane :label="`${widget.widgetData.component.title}组件`" name="widget">
            <el-scrollbar>
                <!-- 图片列表 -->
                <row-content :widget="widget" />

                <el-collapse modelValue="1">
                    <el-collapse-item title="轮播设置" name="1">
                        <layout-pane label="自动播放">
                            <el-switch v-model="widget.widgetData.eles.customFeature.autoplay" />
                        </layout-pane>

                        <el-divider></el-divider>
                        <layout-pane label="播放间隔">
                            <si-input-number
                                v-model="widget.widgetData.eles.customFeature.interval"
                                :min="0"
                                label="秒数"
                            />
                        </layout-pane>
                    </el-collapse-item>
                </el-collapse>

                <!-- 元素可见设置 -->
                <row-element-visible :widget="widget" />
            </el-scrollbar>
        </el-tab-pane>

        <el-tab-pane label="组件样式" name="style">
            <el-scrollbar>
                <el-collapse modelValue="1">
                    <el-collapse-item title="组件设置" name="1">
                        <!-- 大小 -->
                        <row-size :widget="widget" />

                        <!-- 位置 -->
                        <el-divider></el-divider>
                        <row-position :widget="widget" />

                        <el-divider></el-divider>
                        <si-border-radius v-model="widget.widgetData.eles.customFeature.picBorderRadius" />

                        <el-divider></el-divider>
                        <layout-pane label="指示">
                            <si-color-picker
                                v-model="widget.widgetData.eles.customFeature.indicatorColor"
                                label="默认色"
                                show-alpha
                            />
                            <si-color-picker
                                v-model="widget.widgetData.eles.customFeature.indicatorActiveColor"
                                label="选中色"
                                show-alpha
                            />
                        </layout-pane>
                    </el-collapse-item>
                </el-collapse>
            </el-scrollbar>
        </el-tab-pane>
    </el-tabs>
</template>

<script>
import { defineComponent, toRefs, computed } from 'vue'
import LayoutPane from '@/components/setting-pane/layout-pane'
import {
    SiInputNumber,
    SiBorderRadius,
    SiColorPicker
} from '@/components/setting-pane/setting-item'
import {
    RowContent,
    RowPosition,
    RowSize,
    RowElementVisible
} from '../../widget-setting-row'
export default defineComponent({
    name: 'CarouselSetting',
    components: {
        LayoutPane,
        SiInputNumber,
        SiBorderRadius,
        SiColorPicker,
        RowContent,
        RowPosition,
        RowSize,
        RowElementVisible
    },
    props: {
        widget: {
            type: Object,
            default: () => ({})
        }
    },
    setup(props) {
        const { widget } = toRefs(props)

        const picList = computed({
            get: () => widget.value.widgetData.eles.content || [],
            set: val => widget.value.widgetData.eles.content = val
        })

        const row = computed({
            get: () => widget.value.widgetData.eles.customFeature.row,
            set: val => {
                widget.value.widgetData.eles.customFeature.row = val
                const picNum = (col.value * val) - picList.value.length
                if (picNum >= 0) {
                    picList.value.push(...[...new Array(picNum).keys()].map(() => ({
                        title: '标题',
                        pic: '',
                        customFeature: {
                            action: ''
                        }
                    })))
                } else {
                    picList.value.splice(picNum, -picNum)
                }
            }
        })

        const col = computed({
            get: () => widget.value.widgetData.eles.customFeature.col,
            set: val => {
                widget.value.widgetData.eles.customFeature.col = val
                const picNum = (row.value * val) - picList.value.length
                if (picNum >= 0) {
                    picList.value.push(...[...new Array(picNum).keys()].map(() => ({
                        title: '标题',
                        pic: '',
                        customFeature: {
                            action: ''
                        }
                    })))
                } else {
                    picList.value.splice(picNum, -picNum)
                }
            }
        })

        return {
            widget,
            row,
            col
        }
    }
})
</script>
